import mx.utils.Delegate;
/**
 * @author pbalogh
 */
class Terminus 
{
	public static var FRICTION:Number = .98;
	private var _clip : MovieClip;

	public var locked : Boolean = false;

	public var speed_y : Number = 0;
	public var speed_x : Number = 0;
	public var mass : Number;

	public function Terminus ( someclip: MovieClip, somemass:Number )
	{
		_clip = someclip;
		mass = somemass;
		//And now, for fun, let's make them draggable....
		_clip.onReleaseOutside = _clip.onRelease = Delegate.create( this, myClipReleased);
		_clip.onPress = Delegate.create( this, myClipPressed);
	}
	
	public function myClipReleased() : Void
	{
		trace("Released clip " + _clip );
		locked = false;
		delete _clip.onEnterFrame;
	}
	
	public function myClipPressed() : Void
	{
		trace("Pressed clip " + _clip );
		locked = true;
		_clip.onEnterFrame = function() 
		{
			this._x = _root._xmouse;
			this._y = _root._ymouse;
		};
	}
	
	public function get _x () : Number {
		return _clip._x;
	}
	public function set _x (x:Number) {
		_clip._x = x;
	}
	
	// Getter/setter for _y
	public function get _y () : Number {
		return _clip._y;
	}
	public function set _y (y:Number) {
		_clip._y = y;
	}
	
	// Getter/setter for _width
	public function get _width () : Number {
		return _clip._width;
	}
	
	// Getter/setter for _height
	public function get _height () : Number {
		return _clip._height;
	}
	
	public function receiveForce( xforce:Number, yforce:Number ) : Void
	{
		
		speed_x += xforce / mass;
		speed_y += yforce / mass;
		
	}	
		
	public function onEnterFrameHandler() : Void
	{
		
		_x += speed_x;
		_y += speed_y;	
		speed_x *= FRICTION;
		speed_y *= FRICTION;
	}
	
}